package com.simple.trade.controller.vm;

import com.simple.common.entity.ResData;
import com.simple.common.entity.controller.BaseController;
import com.simple.common.entity.req.vm.pay.QueryTradeReq;
import com.simple.common.entity.req.vm.pay.RefundTradeReq;
import com.simple.common.entity.vo.pay.QueryTradeRes;
import com.simple.common.entity.vo.pay.RefundTradeRes;
import com.simple.trade.service.vm.QueryTradeService;
import com.simple.trade.service.vm.RefundTradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author yasud
 * @date 2020年10月09日 09:52
 * @description
 */
@RestController
@RequestMapping("/trade")
public class TradeController extends BaseController {

    @Autowired
    QueryTradeService queryTradeService;

    @Autowired
    RefundTradeService refundTradeService;

    /**
     * 查询支付
     * @param req
     * @return
     */
    @PostMapping("/query")
    public ResData<QueryTradeRes> queryTrade(@RequestBody @Validated QueryTradeReq req) {
        req.check();
        ResData<QueryTradeRes> queryTradeResResData = queryTradeService.queryTrade(req);
        return queryTradeResResData;
    }

    /**
     * 退款
     * @param req
     * @return
     */
    @PostMapping("/refund")
    public ResData<RefundTradeRes> refundTrade(@RequestBody @Validated RefundTradeReq req) {
        req.check();
        ResData<RefundTradeRes> refundTradeResResData = refundTradeService.refundTrade(req);
        return refundTradeResResData;
    }
}
